﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Markup;

namespace MapSurface.WidgetSurface
{
    public class Model2Xaml
    {
        private string _fileName;
        const string header= "<s:SurfaceWindow x:Class=\"{0}\"" +
        " xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\"" +
        "xmlns:x=\"http://schemas.microsoft.com/winfx/2006/xaml\"" +
        "xmlns:s=\"http://schemas.microsoft.com/surface/2008\"" +
        "Title=\"{1}\" >{2}</s:SurfaceWindow>";

        public string FileName
        {
            get { return _fileName; }
            set { _fileName = value; }
        }
        private string _xamlCode;

        public string XamlCode
        {
            get { return _xamlCode; }
            set { _xamlCode = value; }
        }

        public Model2Xaml(UIModelElement.UIModel model, string fileXAML)
        {
            string[] param =new string[] {model.XmiFile.Substring(model.XmiFile.Length-3), model.Name,XamlCode};
            _xamlCode = XamlWriter.Save(model.Contains[0]);
            _fileName = fileXAML;
            _xamlCode = String.Format(header, param);

        }
        public void saveFile()
        {
            string[] param = new string[] { _xamlCode };
            System.IO.File.WriteAllLines(_fileName,param);
        }

    }
}
